package net.zzy.pbbot.plugin.anime.api;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.lz1998.pbbot.bot.Bot;
import net.lz1998.pbbot.bot.BotPlugin;
import net.lz1998.pbbot.utils.Msg;
import net.zzy.pbbot.plugin.anime.service.AnimeService;
import onebot.OnebotEvent;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import static net.zzy.pbbot.finalfield.Command.ANIME;

/**
 * @author zhuZhaoYang
 * @date 2021/9/24 14:22
 */
@Component
@Slf4j
public class Anime extends BotPlugin {

    @SneakyThrows
    @Override
    public int onPrivateMessage(@NotNull Bot bot, @NotNull OnebotEvent.PrivateMessageEvent event) {
        String rawMessage = event.getRawMessage();
        String[] messages = rawMessage.split(" ");
        if (!messages[0].equals(ANIME)) {
            return MESSAGE_IGNORE;
        }
        Msg msg = AnimeService.getAnime(messages);
        msg.sendToFriend(bot, event.getUserId());
        return MESSAGE_IGNORE;
    }

    @SneakyThrows
    @Override
    public int onGroupMessage(@NotNull Bot bot, @NotNull OnebotEvent.GroupMessageEvent event) {
        String rawMessage = event.getRawMessage();
        String[] messages = rawMessage.split(" ");
        if (!messages[0].equals(ANIME)) {
            return MESSAGE_IGNORE;
        }
        Msg msg = AnimeService.getAnime(messages);
        msg.sendToGroup(bot, event.getGroupId());
        return MESSAGE_IGNORE;
    }


}
